package com.aranandroid.customview.dialog

import android.content.Context
import androidx.constraintlayout.widget.ConstraintLayout
import android.widget.RelativeLayout
import android.view.LayoutInflater
import android.view.View

class DialogLayout(context: Context, childLayoutId: Int) :
    ConstraintLayout(context) {
    lateinit var relativeLayout: RelativeLayout
    var inflate: View

    /**
     * 初始化固定控件
     *
     * @param context
     */
    private fun initView(context: Context, childLayoutId: Int ) {
        relativeLayout = inflate.findViewById(R.id.content)
        val view = inflate(context, childLayoutId, null)
        view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        val params = LayoutParams(
            LayoutParams.MATCH_PARENT,
            view.measuredHeight
        )
        view.layoutParams = params
        relativeLayout.addView(view)
    }

    /**
     * 构造方法
     *
     * @param context
     */
    init {
        inflate = LayoutInflater.from(context).inflate(R.layout.dialog_base, this)
        initView(context, childLayoutId)
    }
}